import { Avatar, Form, Input } from 'antd';
import React, { useState } from 'react';
import an58 from '@mmstudio/an000058';
import EditButton from '../../../components/editbutton';
import Uploader from '../../../components/uploader';
import Title from './title';
import api from '../../../atoms/api';
import { Message as M1, Result as R1 } from '../../api/teacher/teacher1/query.api';

export default function Conteat({ data }: {
	data: M1;
}) {
	const [d, setd] = useState(data);
	return <>
		<Title />
		<EditButton dlgtitle='教师管理' onSave={async () => {
			if (!d
				|| !d.teacher_id
				|| !d.degree
				|| !d.picture
				|| !d.teachername
				|| !d.telephone
			) {
				return '缺少必要的参数';
			}
			const res = await an58<R1, M1>(api['/api/teacher/teacher1/query'], 'post', d);
			if (res.ok === true) {
				return true;
			}
			return res.message;
		}}>
			<div>
				<Avatar.Group maxCount={1}>
					<Uploader type='image' multiple={false} onChange={(file) => {
						setd({
							...d,
							picture: file
						});
					}} /></Avatar.Group>
				<Form.Item required label="编号">
					<Input value={d.teacher_id} onChange={(e) => {
						setd({
							...d,
							teacher_id: e.target.value
						});
					}} />
				</Form.Item>
				<Form.Item required label="姓名">
					<Input value={d.teachername} onChange={(e) => {
						setd({
							...d,
							teachername: e.target.value
						});
					}} />
				</Form.Item>
				<Form.Item required label="性别">
					{/* <Radio.Group onChange={(e) => {
						setd({
							...d,
							type: e.target.value
						});
					}} value={d.type}>
						<Radio value={'男'}>男</Radio>
						<Radio value={'女'}>女</Radio>
					</Radio.Group> */}
				</Form.Item>
				<Form.Item required label="学历">
					{/* <Select
						optionFilterProp="children"
						filterOption={(input, option) => {
							return option.children.indexOf(input) >= 0;
						}}
						placeholder='请选择专业名称'
						value={d.degree}
						defaultValue={data.degree}
						onChange={(e) => {
							setd({
								...d,
								degree: e
							});
						}} >
						{dict.map((it) => {
							return <Select.Option key={it.value} value={it.value} >{it.value}</Select.Option>;
						})}
					</Select> */}
				</Form.Item>
				<Form.Item required label="专业">
					<Input value={d.teacher_id} onChange={(e) => {
						setd({
							...d,
							teacher_id: e.target.value
						});
					}} />
				</Form.Item>
				<Form.Item required label="联系方式">
					<Input value={d.telephone} onChange={(e) => {
						setd({
							...d,
							telephone: e.target.value
						});
					}} />
				</Form.Item>
			</div>
		</EditButton>
	</>;
}
